package com.newbb.services;

import java.io.Serializable;

import javax.persistence.EntityManager;

import com.newbb.database.NewBBEntityManager;
import com.newbb.entity.Student;

public class DatabaseService implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	EntityManager em = NewBBEntityManager.get().createEntityManager();
	
	public Student getStudent(){
		try{			
			return (Student)em.createQuery("SELECT FROM "+Student.class.getName()+" AS stu WHERE stu.lastName = 'Dudek' ORDER BY stu.lastName DESC").getResultList().get(0);
		}
		finally{
			//em.close();
		}
	}
	
	public void addStudent(Student student){
		try{
			em.persist(student);
		}
		finally{
			//em.close();
		}
	}
}
